package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 卡尼奶
 * @Date 2022/5/18 11:12
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService trademarkService;

    /**
     * 分页查询品牌信息
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getBaseTrademarkPage(@PathVariable Long page,@PathVariable Long limit){
        Page<BaseTrademark> pages = new Page<>(page,limit);
        pages = trademarkService.page(pages);
        return Result.ok(pages);
    }

    /**
     * 添加品牌信息
     * @param baseTrademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result addTrademark(@RequestBody BaseTrademark baseTrademark){
        trademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 根据id查询品牌信息
     * @param id
     * @return
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademarkById(@PathVariable Long id){
        BaseTrademark trademark = trademarkService.getById(id);
        return Result.ok(trademark);
    }

    /**
     * 根据ID修改品牌信息
     * @param baseTrademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result updateTrademark(@RequestBody BaseTrademark baseTrademark){
        trademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 根据id删除品牌信息
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result removeBaseTrademarkById(@PathVariable Long id){
        trademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 获取品牌属性
     * @return
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        return Result.ok(trademarkService.list());
    }

}
